//
//  HandOverCell.m
//  koubei
//
//  Created by 李彦宏 on 2018/5/4.
//  Copyright © 2018年 朱圳. All rights reserved.
//交接流程cell

#import "HandOverCell.h"

@implementation HandOverCell
//类方法快速创建cell
+(instancetype)cellwithTableview:(UITableView *)tableview{
    
    // 1.创建cell
    static NSString *ID = @"cell";
    HandOverCell * cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[HandOverCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return  cell;
    
}
/**
 *  cell的初始化方法，一个cell只会调用一次
 *  一般在这里添加所有可能显示的子控件，以及子控件的一次性设置
 */
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //添加UI控件
        [self setUI];
    }
    return self;
}
-(void)setUI{
    UILabel *lb1=[[UILabel alloc]init];
    lb1.text=@"1.";
    lb1.textColor=[UIColor blackColor];
    self.numberLb=lb1;
    lb1.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:lb1];
    [lb1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
    make.left.equalTo(self.contentView.mas_left).offset(10);
        make.width.mas_equalTo(20);
        
    }];
    UIButton *Btn=[[UIButton alloc]init];
    self.SelectBtn=Btn;
    [Btn setImage:[UIImage imageNamed:@"stu-ka1"] forState:UIControlStateNormal];
    [Btn addTarget:self action:@selector(BtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:Btn];
    
    [Btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.width.mas_equalTo(35);
        make.height.mas_equalTo(35);
    }];
    
    UILabel *lb2=[[UILabel alloc]init];
    lb2.numberOfLines=0;
    lb2.textAlignment=NSTextAlignmentLeft;
    self.contenLb=lb2;
//    lb2.text=@"3.通过Masonry获取cell的自适应高度创建tableview时，必须给一个估计高度：_tableView.estimatedRowHeight = 175; 需要给cell高度估计值，可以随便给，但不能不给";
    [self.contentView addSubview:lb2];
    
    [lb2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lb1.mas_right).offset(8);
        make.top.equalTo(self.contentView.mas_top).offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
        make.right.equalTo(Btn.mas_left).offset(-8);
    }];

}

-(void)BtnAction:(UIButton *)send{
    _Handmodel.Select=!_Handmodel.Select;
    if(_Handmodel.Select){
        [send setImage:[UIImage imageNamed:@"stu-ka"] forState:UIControlStateNormal];
        
    }else{
        [send setImage:[UIImage imageNamed:@"stu-ka1"] forState:UIControlStateNormal];
    }
    if(_HandDeleget){
        if([_HandDeleget respondsToSelector:@selector(clockAction:withModel:)]){
            [_HandDeleget clockAction:send withModel:_Handmodel];
        }
    }
}
-(void)setHandmodel:(HandOverModel *)Handmodel{
    _Handmodel=Handmodel;
    
    self.numberLb.text=_Handmodel.contentID;
    self.contenLb.text=_Handmodel.content;
    if(_Handmodel.Select){
        [self.SelectBtn setImage:[UIImage imageNamed:@"stu-ka"] forState:UIControlStateNormal];
        
    }else{
        [self.SelectBtn setImage:[UIImage imageNamed:@"stu-ka1"] forState:UIControlStateNormal];
    }
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
